package dq.thread;

import java.lang.ref.WeakReference;

/**
 * @Author: Dang Qi
 * @Date: 2021/3/20  13:39
 * @Description:
 */
public class ComReSort {
    public static int a,b;
    public static int x,y;

    public static void main(String[] args) throws InterruptedException {

        int i = 0;
        while(true){
            i++;
            a=0; b=0;
            x=0; y=0;
            Thread one = new Thread(()->{
                a = 1;
                x = b;
            });
            Thread other = new Thread(()->{
               b = 1;
               y = a;
            });
            one.start(); other.start();
            one.join(); other.join();

            if(x==0 && y == 0){
                System.out.printf("第%d次，x=%d, y=%d\n", i, x, y);
                break;
            }
        }

    }
}
